﻿Imports Mystery

Public Class ContentTableAttr
    Inherits MysteryDefaultClassAttribute

    Public Property implementing_type As Type

    Private generic As Type = GetType(ContentTableCreator(Of ))
    Private creator As IControlCreator

    Public Overrides Sub setUp()
        If implementing_type IsNot Nothing Then
            implementing_type.GetInterfaceMap(GetType(IControlCreator))
        Else
            implementing_type = generic.MakeGenericType(used_in)
        End If

        creator = getGlobalObject(Of FastActivator).createInstance(implementing_type)

    End Sub

    Public Function createControl() As UserControl
        Return creator.createControl()
    End Function
End Class

Public Class ContentTableContentFilterAttr
    Inherits MysteryDefaultClassAttribute

    Public Property implementing_type As Type

    Private activator As IActivator


    Public Overrides Sub setUp()
        If implementing_type IsNot Nothing Then
            implementing_type.GetInterfaceMap(GetType(IContentFilter))
            activator = getGlobalObject(Of FastActivator).getActivator(implementing_type)
        End If

    End Sub

    Public Function getFilter() As IContentFilter
        If activator Is Nothing Then Return Nothing
        Return activator.createInstance()
    End Function
End Class


Public Class ContentTableContentGatherAttr
    Inherits MysteryDefaultClassAttribute

    Public Property implementing_type As Type

    Private activator As IActivator
    Private generic As Type = GetType(ContentTypeDefaultRetriver(Of ))

    Public Overrides Sub setUp()
        If implementing_type IsNot Nothing Then
            implementing_type.GetInterfaceMap(GetType(IContentRetriver))
        Else
            implementing_type = generic.MakeGenericType(used_in)
        End If

        activator = getGlobalObject(Of FastActivator).getActivator(implementing_type)

    End Sub

    Public Function retriveContents() As IEnumerable(Of IContent)
        Dim retriver As IContentRetriver = activator.createInstance()
        Return retriver.getAllTheContents
    End Function
End Class



Public Class ContentTableCreator(Of T As IContent)
    Implements IControlCreator

    Public Function createControl() As System.Windows.Controls.UserControl Implements IControlCreator.createControl
        Dim result As New ContentsTable
        result.generateControl(Of T)()
        result.new_content_filter = GetType(T).getMysteryAttribute(Of ContentTableContentFilterAttr)().getFilter()
        Dim gather As ContentTableContentGatherAttr = GetType(T).getMysteryAttribute(Of ContentTableContentGatherAttr)()
        result.showContents(gather.retriveContents())
        Return result
    End Function
End Class

